package ThreadTest;

class SynThread01 implements Runnable{

    private int ticket=10;


    @Override
    public void run() {

        for (int i=0;i<50;i++){
            try {
                Thread.sleep(3000);
            }catch (Exception e){}
            if (this.ticket>0){
                System.out.println(Thread.currentThread().getName()+"卖票，剩余:"+this.ticket--);
            }
        }


    }
}


public class SynDemo01 {
    public static void main(String[] args) {
         SynThread01 synThread01=new SynThread01();
        new Thread(synThread01,"票贩子A").start();
        new Thread(synThread01,"票贩子B").start();
        new Thread(synThread01,"票贩子C").start();

    }
}
